import Vue from 'vue';
import Vuex from 'vuex'
import store from './vuex/store'
import iView from 'iview';
import VueRouter from 'vue-router';
import Routers from './router';
import Util from './libs/util';
import App from './app.vue';
import VueVideoPlayer from 'vue-video-player'
import 'videojs-contrib-hls/dist/videojs-contrib-hls'
import 'iview/dist/styles/iview.css';
import 'element-ui/lib/theme-default/index.css'
import { Tabs,TabPane } from 'element-ui'

//import VueClipboard from 'vue-clipboard'
/*import VueHtml5Editor from 'vue-html5-editor'*/
/*import EditorOptions from './utils/vue-html5-editor-options'*/
import 'font-awesome/css/font-awesome.css'
import { getToken } from './utils/auth'

/*VueVideoPlayer.config({
    youtube: true, // default false
    switcher: true, // default true
    hls: true // default true
})*/

Vue.use(VueRouter);
Vue.use(Vuex)
Vue.use(iView);
Vue.use(Tabs)
Vue.use(TabPane)
Vue.use(VueVideoPlayer)
//Vue.use(VueClipboard)
/*Vue.use(VueHtml5Editor,EditorOptions)*/
// 路由配置
const RouterConfig = {
    mode: 'hash',
    routes: Routers
};
const router = new VueRouter(RouterConfig);
const whiteList = ['/login'];
router.beforeEach((to, from, next) => {
    //console.log(to)
    iView.LoadingBar.start();
    if (getToken()){
        if (to.path === '/login') {
            next({ path: '/' });
        } else {
            next();
        }
    }else {
        if (whiteList.indexOf(to.path) !== -1) {
            next()
        } else {
            next('/login');
            //iView.LoadingBar.finish();
        }
    }
    Util.title(to.meta.title);
    next();
});

router.afterEach((to, from, next) => {
    iView.LoadingBar.finish();
    window.scrollTo(0, 0);
});

new Vue({
    el: '#app',
    router: router,
    store,
    render: h => h(App)
});
